﻿//---------------------------------------------------------------------------
// <summary>
// Writes an IPFS postback body using CurrentFormData which
// was extracted from a previous request
// </summary>
//---------------------------------------------------------------------------

namespace InfoPathExtractionRules
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using Microsoft.VisualStudio.TestTools.WebTesting;

    /// <summary>
    /// Writes an IPFS postback body using CurrentFormData which
    /// was extracted from a previous request.
    /// </summary>
    public class WriteFormsServicesPostBackBody : WebTestRequestPlugin
    {
        /// <summary>
        /// Writes an IPFS postback body using CurrentFormData which
        /// was extracted from a previous request.
        /// </summary>
        /// <param name="sender">The object that fired the event.</param>
        /// <param name="e">A PreRequestEventArgs object.</param>
        public override void PreRequest(object sender, PreRequestEventArgs e)
        {
            StringHttpBody body = (StringHttpBody)e.Request.Body;
            body.BodyString = IPExtractionUtility.SubstituteCurrentFormData(body.BodyString, e.WebTest.Context, Format.FormsServicesPostBackBody);
        }
    }
}
